// src/store/userStore.js
import { defineStore } from 'pinia'

import axios from '@/utils/axios'

export const useUserStore = defineStore('user', {
    state: () => ({
        username: '',
        role: 'anonymous',
        token: null
    }),
    actions: {
        setAuthData({ username, role, token }) {
            this.username = username
            this.role = role
            this.token = token
        },
        async logout() {
            this.$reset()
            this.username = '';
            this.role = 'anonymous';
            this.token = null;
            delete axios.defaults.headers.common.Authorization
        },
    },
    persist: true
})